package com.tarena.lbs.attach.timer;

import com.tarena.lbs.attach.utils.FileUtil;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

@Slf4j
@Component
public class TimerDeprecatedAttach {

    @Value("${image_path}")
    private String imagePath;

    @XxlJob("deleteAttach")
    public void deleteAttachDeprecated() {
        log.info("定时任务开始执行");
        SimpleDateFormat sdf = new SimpleDateFormat("/MM/dd");
        String datePath = sdf.format(new Date());
        File file = new File(imagePath + datePath);
        if (file.exists()){
            FileUtil.deleteFolder(file);
        }
        log.info("定时任务执行完毕，删除了{}的图片",datePath);
    }
}
